package com.huifer.wgx.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * <p>Title : FileEntity </p>
 * <p>Description : </p>
 *
 * @author huifer
 * @date 2019-03-20
 */
@Entity
@Table(name = "t_file", schema = "at15", catalog = "")
public class FileEntity {

    private Long fileId;
    private String fileName;
    private String fileType;
    private byte[] fileData;
    private Long personnelId;
    private Long workId;
    private String cPath;
    private Collection<FieldLineEntity> tFieldLinesByFileId;
    private Collection<FieldPointEntity> tFieldPointsByFileId;
    private PersonnelEntity tPersonnelByPersonnelId;
    private Collection<RtkPointEntity> tRtkPointsByFileId;
    private WorkEntity tWorkByWorkId;

    @Id
    @Column(name = "file_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getFileId() {
        return fileId;
    }

    public void setFileId(Long fileId) {
        this.fileId = fileId;
    }

    @Basic
    @Column(name = "file_name")
    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Basic
    @Column(name = "file_type")
    public String getFileType() {
        return fileType;
    }

    public void setFileType(String fileType) {
        this.fileType = fileType;
    }

    @Basic
    @Column(name = "file_data")
    public byte[] getFileData() {
        return fileData;
    }

    public void setFileData(byte[] fileData) {
        this.fileData = fileData;
    }

    @Basic
    @Column(name = "personnel_id")
    public Long getPersonnelId() {
        return personnelId;
    }

    public void setPersonnelId(Long personnelId) {
        this.personnelId = personnelId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        FileEntity that = (FileEntity) o;
        return Objects.equals(fileId, that.fileId) &&
                Objects.equals(fileName, that.fileName) &&
                Objects.equals(fileType, that.fileType) &&
                Arrays.equals(fileData, that.fileData) &&
                Objects.equals(personnelId, that.personnelId);
    }

    @Override
    public int hashCode() {
        int result = Objects.hash(fileId, fileName, fileType, personnelId);
        result = 31 * result + Arrays.hashCode(fileData);
        return result;
    }

    @OneToMany(mappedBy = "tFileByFileId")
    @JsonIgnore
    public Collection<FieldLineEntity> gettFieldLinesByFileId() {
        return tFieldLinesByFileId;
    }

    public void settFieldLinesByFileId(
            Collection<FieldLineEntity> tFieldLinesByFileId) {
        this.tFieldLinesByFileId = tFieldLinesByFileId;
    }

    @OneToMany(mappedBy = "tFileByFiledId")
    @JsonIgnore
    public Collection<FieldPointEntity> gettFieldPointsByFileId() {
        return tFieldPointsByFileId;
    }

    public void settFieldPointsByFileId(
            Collection<FieldPointEntity> tFieldPointsByFileId) {
        this.tFieldPointsByFileId = tFieldPointsByFileId;
    }

    @ManyToOne
    @JoinColumn(name = "personnel_id", referencedColumnName = "personnel_id",insertable = false,updatable = false)
    public PersonnelEntity gettPersonnelByPersonnelId() {
        return tPersonnelByPersonnelId;
    }

    public void settPersonnelByPersonnelId(PersonnelEntity tPersonnelByPersonnelId) {
        this.tPersonnelByPersonnelId = tPersonnelByPersonnelId;
    }

    @OneToMany(mappedBy = "tFileByFileId")
    @JsonIgnore
    public Collection<RtkPointEntity> gettRtkPointsByFileId() {
        return tRtkPointsByFileId;
    }

    public void settRtkPointsByFileId(
            Collection<RtkPointEntity> tRtkPointsByFileId) {
        this.tRtkPointsByFileId = tRtkPointsByFileId;
    }

    @ManyToOne
    @JoinColumn(name = "work_id", referencedColumnName = "work_id",insertable = false,updatable = false)
    public WorkEntity gettWorkByWorkId() {
        return tWorkByWorkId;
    }

    public void settWorkByWorkId(WorkEntity tWorkByWorkId) {
        this.tWorkByWorkId = tWorkByWorkId;
    }

    @Basic
    @Column(name = "work_id")
    public Long getWorkId() {
        return workId;
    }

    public void setWorkId(Long workId) {
        this.workId = workId;
    }

    @Basic
    @Column(name = "file_cpath")
    public String getcPath() {
        return cPath;
    }

    public void setcPath(String cPath) {
        this.cPath = cPath;
    }
}
